#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
int pow(int a, int b) {
  int res = 1;
  while(b) {
    if(b & 1)res = (res * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return res;
}

signed main() {
  int t;
  cin >> t;
  while(t--) {
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    int x = pow(2, n);
    // cout << x << endl;
    // cout << pow(a, x) << endl;
    cout << (pow(a, x) * pow(b, x) % MOD * pow(c, x)) % MOD << endl;
  }
  return 0;
}